<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px; width: 100%">
    <el-col>
      <strong v-if="isRoot"><i class="el-icon-s-home" /> {{ treeNode.name }} </strong>
      <span v-else> {{ treeNode.name }} </span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col> {{ treeNode.manager }} </el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="true" @click.native="AddDept">添加部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delDepartments">删除部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepartments">编辑部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'
export default {
  props: {
    //   定义一个props属性
    treeNode: {
      type: Object, // 对象类型
      required: true // 要求对方使用您的组件的时候 必须传treeNode属性 如果不传 就会报错
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  }, methods: {
    async delDepartments() {
      try {
        // 二次校验
        await this.$confirm('是否确认删除')
        // 发送请求删除
        await delDepartments(this.treeNode.id)
        // 提示用户
        this.$message.success('删除成功')
        // 更新页面
        this.$emit('delDepartment')
      } catch (error) {
        console.log(error)
      }
    },
    AddDept() {
      this.$emit('AddDept', this.treeNode)
    },
    editDepartments() {
      this.$emit('editDepartments', this.treeNode)
    }

  }

}
</script>

<style>

</style>
